package org.fuxia.im.core.utils;

public class ByteIterator implements ECIterator<byte[]>
{

	private byte[]	data;
	private int		index	= -1;
	private int		count;

	public static ECIterator<byte[]> getIterator(byte[] originData)
	{
		ByteIterator iterator = new ByteIterator(originData);
		return iterator;
	}

	private ByteIterator(byte[] originData)
	{
		this.data = originData;
		this.count = originData.length;
	}

	public boolean hasNext()
	{
		return (index + 1) < count;
	}

	public Object next()
	{
		return data[++index];
	}

	public byte[] nextN(int n)
	{
		if (count - index < n)
		{
			n = count - index;
		}

		byte[] result = new byte[n];
		for (int i = 0; i < n; i++)
		{
			result[i] = data[++index];
		}
		return result;
	}

}
